<%@page import="school.entity.Student"%>
<%@page import="school.dao.StudentDao"%>
<%@page import="school.dao.StudentDaoI"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>My JSP 'doLogin.jsp' starting page</title>

	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->

  </head>
  
  <body>
    This is my JSP page. <br>
    <%
    	request.setCharacterEncoding("utf-8");
    	String u=request.getParameter("uname");
    	String p=request.getParameter("pass");//request.getParameterValues("pass")[0];
    	
     %>
     
     <%
       StudentDaoI stdao=new StudentDao();
       Student stu=stdao.login(Long.parseLong(u),p);
       	
       if(stu==null){
       		request.setAttribute("msg", "登录信息非法");
       		request.getRequestDispatcher("login.jsp").forward(request, response);
      		return;
       }
      // request.getRequestDispatcher("welcome.jsp").forward(request, response);
     session.setAttribute("USER_LOGIN",stu);
     //长久的存入cookie
     Cookie c1=new Cookie("user_name",u);
     c1.setMaxAge(86400*7);
     c1.setHttpOnly(true);//防止js获得
     //!!!!
     c1.setPath("/");//!!!!
     response.addCookie(c1);
     response.sendRedirect("welcome.jsp");
     //response.sendRedirect("https://www.baidu.com/s?wd="+u);		
      %>
       
  </body>
</html>
